/**
 * @file main.c
 * @author your name (you@domain.com)
 * @brief 顺序存储线性表的实现
 * @version 0.1
 * @date 2023-02-19
 * 
 * @copyright Copyright (c) 2023
 * 
 */
#include <stdio.h>
#include <stdlib.h>
#include "sqlist.h"


int main(int argc,char *argv[])
{
    sqlist *list = NULL;
    sqlist *list2 = NULL;

    datatype arr[] = {12,23,34,45,56};
    datatype arr2[] = {78,34,56,13};
    int i;
    int err;
    
    // 创建线性表
    sqlist_init(&list);
    if(list == NULL)
    {
        fprintf(stderr,"sqlist_create() failed\n");
        exit(1);
    }

    // 线性表插入数据
    for(i=0;i<sizeof(arr)/sizeof(*arr);i++)
    {
        if((err = sqlist_insert(list,0,&arr[i])) != 0)
        {
            if(err == -1)
                fprintf(stderr,"The arr is full.\n");
            else if(err == -2)
                fprintf(stderr,"The positon you want to insert is wrong.\n");
            else
                fprintf(stderr,"Err!\n");

            exit(1);
        }
    }

    sqlist_display(list);   //线性表遍历


#if 0
    //删除一个指定下标的元素元素
    sqlist_delete(list,1);  
    sqlist_display(list);   //线性表遍历
#endif

    // 创建线性表
    list2 = sqlist_create();
    if(list2 == NULL)
    {
        fprintf(stderr,"sqlist_create failed\n");
        exit(1);
    }


    // 线性表插入元素
    for(i=0;i<sizeof(arr2)/sizeof(*arr2);i++)
    {
        if((err = sqlist_insert(list2,0,&arr2[i])) != 0)
        {
            if(err == -1)
                fprintf(stderr,"The arr is full.\n");
            else if(err == -2)
                fprintf(stderr,"The positon you want to insert is wrong.\n");
            else
                fprintf(stderr,"Err!\n");
            
            exit(1);
        }
    }

    sqlist_display(list2);  //线性表遍历


    // 线性表合并
    sqlist_union(list,list2);
    sqlist_display(list);       //线性表遍历


    // 释放线性表
    sqlist_destroy(list2);
    sqlist_destroy(list);

    exit(0);
}

